<?php
/**
 * Created by PhpStorm
 * User: whh
 * Date: 2023/10/30
 * Time: 20:43
 */

namespace app\reception\controller;


use think\Db;

class Push extends Common
{
    protected $middleware = [
        'VerifyAuth' => ['except' => []],
    ];

    public function jumpCallback()
    {
        $params = $this->request->param();
        $result = $this->validate($params, 'app\reception\validate\PushValidate.jumpCallback');
        if (true !== $result) {
            return errJson($result);
        }
        return sucJson();
    }

    /**
     * 推送另外一个快应用
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getPushHapLink()
    {
        $pageParam = input('pageParam');
        $params = json_decode($pageParam, true);
        $push_link = '';
        if (!$this->user->channel_id || $this->isBlack || $this->user->auditor) {
            if ($this->uid != 25297448){
                return errJson('无推送链接');
            }
        } elseif (!ipUnblocked($this->user)) {
            return errJson('无推送链接');
        }
        if (isset($params['token']) && $params['token'] != '') {
            $push_link = \app\backstage\model\Link::where("token", $params['token'])->value('push_link');
            if ($push_link) {
                unset($params['token']);
                $queryString = http_build_query($params);
                $push_link = $push_link."&".$queryString;
            }
        }
        if ($push_link){
            return sucJson(['push_link' => $push_link]);
        }else{
            return errJson('无推送链接');
        }

    }
}